"""
    log.py


    Steven Hepting
    shepting@gmail.com
"""

import logging
import logging.handlers

# Make a root logger for all handlers to add to
root = logging.getLogger()
root.setLevel(logging.DEBUG)

# Make a console handler for basic shell output
console = logging.StreamHandler()
console.setLevel(logging.DEBUG)
message_format = "%(levelname)8s %(message)s"
time_format = "%H:%M:%S"
console.setFormatter(logging.Formatter(message_format, time_format))
root.addHandler(console)

# Make a file handler for debugging long-running tasks
rotate = logging.handlers.RotatingFileHandler("protospec.log", maxBytes=100000, 
                                     backupCount=9)
rotate.setLevel(logging.DEBUG)
f = "%(asctime)s %(levelname)8s %(filename)-10s %(lineno)4d %(thread)d %(message)s"
rotate.setFormatter(logging.Formatter(f))
root.addHandler(rotate)

# Make an email handler for critical errors
email = logging.handlers.SMTPHandler("smtp.sasktel.com", "ProtoSpec Server",
                                     "shepting@gmail.com", "Home Status Message")
email.setLevel(logging.CRITICAL)
f = "%(levelname)8s %(filename)-10s %lineno)4d %(message)s"
email.setFormatter(logging.Formatter(f))
root.addHandler(email)
